﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <style>
    </style>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset" style="display:none;">
                <legend>库存详情</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <input type="hidden" id="BillNameID" value="@ViewBag.BillNameID" />
                    <input type="hidden" id="GoodsID" value="@ViewBag.GoodsID" />
                </div>
            </fieldset>
            <script type="text/html" id="toolbarDemo">
                {{#  if( @(Web.Common.Common.IsAuthoritys(26)) == 1){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="ru">其它入库</a>
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="chu">其它出库</a>
                {{#  } }}
            </script>
            <table class="layui-hide" id="table" lay-filter="currentTableFilter"></table>
            <script type="text/html" id="currentTableBar">
                {{#  if( @(Web.Common.Common.IsAuthoritys(26)) == 1 && (d.Type==2 || d.Type==5)){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="delete">删除</a>
                {{#  } }}
           </script>
        </div>
    </div>
    <script src="~/layui/layui.js"></script>
    <script src="~/layuimini/js/lay-config.js"></script>
    <script>
        layui.use(['form', 'table', 'miniTab'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                miniTab = layui.miniTab;

        table.render({
            elem: '#table',
            method: 'post',
            url: '@Url.Action("GoodsStockRunningsListAsync", "GoodsStock")',
            request: {
                pageName: 'PageIndex' //页码的参数名称，默认：page
               , limitName: 'PageSize' //每页数据量的参数名，默认：limit
            },
            where: {
                GoodsID: $('#GoodsID').val(),
                BillNameID: $('#BillNameID').val()
            },
            cellMinWidth:120,
            toolbar: '#toolbarDemo',
            defaultToolbar: [{ layEvent: 'refresh', icon: 'layui-icon-refresh', title: '刷新' }, 'filter', 'exports', 'print'],
            cols: [[
                //{ type: "checkbox", width: 50 },
                { type: 'numbers', title: '序号', width: 50 },
                { field: 'ID', title: 'ID', width: 100, hide: true },
                { field: 'BillName', title: '流程卡' },
                { field: 'CreateTime', title: '出入库时间' },
                //{ field: 'GoodsCode', title: '产品编码' },
                { field: 'GoodsName', title: '产品名称' },
                { field: 'GoodsModel', title: '产品型号' },
                { field: 'TypeName', title: '出入库类型' },
                { field: 'Qty', title: '出入库数量' },
                { field: 'Balance', title: '库存' },
                { fixed: 'right', title: '操作', toolbar: '#currentTableBar', width: 100 }
            ]],
            limits: [10, 20, 30, 50, 100, 100000000],
            limit: 20,
            page: true,
            //skin: 'line',
            //totalRow: true,
            height: 'full-70',
            size:'sm',
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            RefreshTable();
            return false
        });



        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'refresh') {
                RefreshTable();
            } else if (obj.event === 'ru') {
                var index = layer.open({
                    title: '其它入库',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: false,
                    area: ['600px', '400px'],
                    content: '@Url.Action("OtherStockEdit", "GoodsStock")?Type=2&BillNameID=@ViewBag.BillNameID&GoodsID=@ViewBag.GoodsID',
                    end: function () {
                        RefreshTable();
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'chu') {
                var index = layer.open({
                    title: '其它出库',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: false,
                    area: ['600px', '400px'],
                    content: '@Url.Action("OtherStockEdit", "GoodsStock")?Type=5&BillNameID=@ViewBag.BillNameID&GoodsID=@ViewBag.GoodsID',
                    end: function () {
                        RefreshTable();
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('您确定要删除所选数据吗', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: '@Url.Action("OtherStockEditAsync", "GoodsStock")',
                        type: "post",
                        dataType: "json",
                        data: { ID: data.ID, Remark: '' },
                        success: function (obj) {
                            //Info,Success,Warning,Error
                            var type = obj.Type;
                            if (type == 1) {
                                layer.msg(obj.Content,
                                    {
                                        icon: 6, time: 2000
                                    },
                                    function () {
                                        RefreshTable();
                                    });
                            } else {
                                layer.msg(obj.Content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }, function () {
                    return;
                });
                return false;
            }
        });
        function RefreshTable() {
            table.reload('table', {
                where: {
                    GoodsID: $('#GoodsID').val(),
                    BillNameID: $('#BillNameID').val()
                }
            }, 'data');

        }

    });
    </script>
</body>
</html>